﻿using DI;
using Library.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http.ExceptionHandling;

namespace Presentation
{
    /*http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-21#global-error*/
    public class WebApiExceptionLogger : ExceptionLogger
    {
        private readonly ILogger logger;

        public WebApiExceptionLogger()
        {
            this.logger = Bootstrapper.Resolve<ILogger>();
        }

        public override void Log(ExceptionLoggerContext context)
        {
            string message = string.Format("{0} {1}", context.Request.Method, context.Request.RequestUri);
            logger.Log(message, context.Exception);                    
        }
    }
}
